package com.course.chapter5;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

public class AQSDemo1 {
    ReentrantLock lock =new ReentrantLock();
   private volatile  int m =0 ;
   public int next(){
       try {
           TimeUnit.SECONDS.sleep(2);
       } catch (InterruptedException e) {
           e.printStackTrace();
       }
       return m++;
   }

    public static void main(String[] args) {
        AQSDemo1 aqsDemo1 = new AQSDemo1();

        Thread[] th=new Thread[20];
        for (int i = 0; i < 20; i++) {
            th[i] = new Thread(()->{
                System.out.println(aqsDemo1.next());
            });
        }
        for (Thread thread : th) {
            thread.start();
        }

    }
}
